package csc.daonjpa.java.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Component;
import csc.daonjpa.java.domain.Customer;
import csc.daonjpa.java.transaction.TransactionManager;

@Component
public class CustomerDAO {
	/**
	 * @return all accounts from Account table
	 */
	public List<Customer> getCustomers() {
		EntityManager em = TransactionManager.getEntityManager();
		TypedQuery<Customer> query = em.createQuery("SELECT a FROM Customer a", Customer.class);
		List<Customer> customers = null;
		customers = query.getResultList();
		return customers;
	}
	
	/**
	 * Add account to Account table
	 * @param account Account entity that contains mapped with each column in Account table
	 * @return
	 */
	public boolean addCustomer(Customer customer) {
		EntityManager em = TransactionManager.getEntityManager();
		em.persist(customer);
		return true;
	}
	public Customer getCustomer(Long customerId) {
		EntityManager em = TransactionManager.getEntityManager();
		Customer customer = em.find(Customer.class, customerId);
		return customer;
	}
}
